package com.yayo.mangement.response;

public class Response<T> {
    private boolean success;

    private T data;

    private Integer code;

    private String error;

    public Response() {}

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setData(T data) {
        this.data = data;
    }

    public T getData() {
        return data;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getCode() {
        return code;
    }

    public void setError(String error) {
        this.error = error;
    }

    public String getError() {
        return error;
    }

    public static <T> Response<T> ok(T data) {
        Response<T> resp = new Response();
        resp.setCode(200);
        resp.setSuccess(true);
        resp.setData(data);
        return resp;
    }

    public static <T> Response<T> ok() {
        Response<T> resp = new Response();
        resp.setCode(200);
        resp.setSuccess(true);
        return resp;
    }

    public static <T> Response<T> fail(String error) {
        Response<T> resp = new Response();
        resp.setSuccess(false);
        resp.setError(error);
        return resp;
    }

    public static <T> Response<T> fail(Integer code, String error) {
        Response<T> resp = new Response();
        resp.setSuccess(false);
        resp.setCode(code);
        resp.setError(error);
        return resp;
    }

}
